package org.example.ideavr.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.example.ideavr.common.result.PageResult;
import org.example.ideavr.common.result.Result;
import org.example.ideavr.pojo.dto.GamePageQueryDTO;
import org.example.ideavr.pojo.entity.Game;
import org.example.ideavr.service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Tag(name = "Game模块")
@RestController
@RequestMapping("/game")
@Slf4j
public class GameController {

    @Autowired
    GameService gameService;

    @Operation(summary = "游戏新增")
    @PostMapping("/upload")
    public Result<String> gameUpload(@RequestBody Game game){
        log.info("游戏新增：{}",game);
        gameService.gameUpload(game);

        return Result.success();
    }

    @Operation(summary = "游戏分页查询")
    @GetMapping("/page")
    public Result<PageResult> gamePage(GamePageQueryDTO gamePageQueryDTO){
        log.info("游戏分页查询：{}",gamePageQueryDTO);
        PageResult pageResult = gameService.gamePage(gamePageQueryDTO);
        return Result.success(pageResult);
    }

    @Operation(summary = "游戏下载")
    @GetMapping("/download/{game_id}")
    public void gameDownload(@PathVariable Long game_id, HttpServletResponse response) throws IOException {
        log.info("游戏下载：{}",game_id);
        gameService.gameDownload(response,game_id);

    }

    @Operation(summary = "根据id游戏查询")
    @GetMapping("/{game_id}")
    public Result<Game> getGameById(@PathVariable Long game_id){
        log.info("根据id游戏查询：{}",game_id);
        Game game = gameService.getGameById(game_id);
        return Result.success(game);
    }

    @Operation(summary = "游戏更新")
    @PutMapping("/update/{game_id}")
    public Result<String> gameUpdate(@PathVariable Long game_id, @RequestBody Game game){
        log.info("游戏更新：{}",game);
        gameService.gameUpdate(game_id,game);
        return Result.success();
    }

}
